package YAPclient;


import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;


/**
 * This class is for creating little dialogs in which the user can change the volume of the sounds
 * being played during a game
 */

@Deprecated
public class SoundDialog extends JDialog implements ActionListener{
	
	private static final long serialVersionUID = 2373348476482460369L;
	
	private JSlider jslVolume = new JSlider();
	private JLabel lblVolume = new JLabel("Volume");
	private JButton btnConfirm = new JButton("OK");
		
	
	/**
	 * Creates and opens a new SoundDialog
	 * @param owner Frame which owns this dialog
	 */
	
	public SoundDialog(JFrame owner){
			
		super(owner, "Sound Settings");
						 
		this.addComponents();
		this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		this.pack();
		this.setLocationRelativeTo(null);
		this.setVisible(true);
			
	}
		
		private void addComponents(){
			
			this.getContentPane().setLayout(new GridBagLayout());
			GridBagConstraints c = new GridBagConstraints();
			
			c.insets = new Insets(10,10,10,10);
			
			c.gridx = 0; c.gridy = 0;
			this.getContentPane().add(lblVolume,c);
			
			c.gridx = 1; //c.gridy = 0;
			this.getContentPane().add(jslVolume,c);
			
			c.gridx = 0; c.gridy = 1;
			c.gridwidth = 2; c.anchor=GridBagConstraints.CENTER;
			this.getContentPane().add(btnConfirm,c);
			
			btnConfirm.addActionListener(this);
			
			
			//TODO set the slider's max/min/curr values passend je nach dem ob Control.MASTER_GAIN oder Contorl.VOLUME
			//verwendet werden soll (müssen wir noch besprechen& ausprobieren)
			
			//jslVolume.setMinimum(0);
			//jslVolume.setMaximum(10);
			//jslVolume.setValue((int) DataModul.parseThread.getVolume());
			
			jslVolume.addChangeListener(new ChangeListener(){
				public void stateChanged(ChangeEvent arg0) {
					
					//TODO (hängt von verwendeter control/minmaxwerten des sliders ab)
					//DataModul.parseThread.setVolume(jslVolume.getValue()*10000.0f);
				
				}
			});
			

		}
		
		
		/**
		 * Closes the dialog if the user presses the OK button
		 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
		 */
		@Override
		public void actionPerformed(ActionEvent e) {
			if(e.getSource()==btnConfirm){
				this.dispose();
			}
		}
}